package cardGame;

import java.util.Random;

import cardGame.Card.FaceValue;

public class HoyleDeck implements Deck {

	private Card[] deck = new Card[52];
	private int numLeft = deck.length;

	public HoyleDeck() {
		int i = 0;
		for (Card.Suit suit : Card.Suit.values()) {
			for (FaceValue faceValue : Card.FaceValue.values()) {
				getDeck()[i++] = new Card(suit, faceValue);
			}
		}
	}

	@Override
	public int getNumCards() {
		return getDeck().length;
	}

	@Override
	public void shuffle() {
		Card p; // pulled card (starting from top)
		Random rGen = new Random();		//random dumber
		int numCardsLeft=deck.length;	//card that haven't been shuffled

		for (int i = deck.length-1; i >= 0; i--) {
			int randomNumber = rGen.nextInt(numCardsLeft--);
			p = deck[i]; 		// Takes card out 
			deck[i] = deck[randomNumber]; // Puts random card in spot
			deck[randomNumber] = p; // places pulled card into random spot
		}
	}

	@Override
	public Card deal() {
		if (numLeft > 0)
			return getDeck()[--numLeft];
		return null;
	}

	public Card[] getDeck() {
		return deck;
	}

}
